/**
 * 添加或者修改页面
 */
var MainInfoInfoDlg = {
    data: {
        id: "",
        isDel: "",
        relXqId: "",
        wxXm: "",
        tswxXm: "",
        sgfa: "",
        gcys: "",
        ftl: "",
        showDay: "",
        startDate: "",
        state: "",
        createPerson: "",
        createDate: "",
        updatePerson: "",
        updateDate: ""
    }
};


layui.use(['form', 'admin', 'ax', 'laydate', 'upload', 'formSelects', 'tree', 'layer'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var tree = layui.tree;
    var layer = layui.layer;
    var upload = layui.upload;

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/mainInfo/list?id=" + Feng.getUrlParam("main_id"));
    var result = ajax.start();
    // console.log(result.data[0])
    $("#main_id").val(result.data[0].id)
    $("#wxXm").val(result.data[0].wxXm)


    $("#vote_day_length").blur(function () {
        let value = $("#vote_day_length").val();
        value = value.replace(/[^\d]/g, '').replace(/^0{1,}/g, '');
        if (value != '')
            value = parseFloat(value).toFixed(0);
        else
            value = parseFloat(5).toFixed(0);
        $("#vote_day_length").val(value);
    })


    //渲染时间选择框
    var laydate = layui.laydate;
    laydate.render({
        elem: '#vote_start_date' //指定元素
        // 只有控件被点击才能消失(防止一闪而过)
        , trigger: 'click'
    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {

        var ajax = new $ax(Feng.ctxPath + "/voteInfo/startVote", function (data) {
            Feng.success("发起成功！");
            parent.layer.closeAll();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function () {
        parent.layer.closeAll();
    });

});